<?php
class lapkeuangan_model extends CI_Model
{
	// Call the module constructor
	function __construct(){
		parent::__construct();
	}
	
	function getMutasijual($tgl,$tgl1,$tipebayar)
	{
		if ($tipebayar==="B")
		{
			if ($tgl != "" && $tgl1 !="")
			{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out,
C.KodeBank,D.Bankname from kwitansipenjualan A,transaction_kwitansi B,mutasi_bank C,master_bank D
where A.NoKwitansi=B.NoKwitansi and A.NoKwitansi = C.NoKwitansi and C.Kodebank = D.KodeBank
and A.Typebayar='BANK' and A.Active='1' and A.CreatedOn between '".$tgl."' and '".$tgl1."'");
			}else{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out,
C.KodeBank,D.Bankname from kwitansipenjualan A,transaction_kwitansi B,mutasi_bank C,master_bank D
where A.NoKwitansi=B.NoKwitansi and A.NoKwitansi = C.NoKwitansi and C.Kodebank = D.KodeBank
and A.Active='1' and A.Typebayar='BANK' group by A.NoKwitansi");
			}	
		}else if ($tipebayar==="G")
		{
			if ($tgl != "" && $tgl1 !="")
			{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out,
C.Nogiro,C.Bankname from kwitansipenjualan A,transaction_kwitansi B,mutasi_giro C
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi
and A.Typebayar='GIRO' and A.Active='1' and A.CreatedOn between '".$tgl."' and '".$tgl1."'");
			}else{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out,
C.Nogiro,C.Bankname from kwitansipenjualan A,transaction_kwitansi B,mutasi_giro C
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi
and A.Active='1' and A.Typebayar='GIRO' group by A.NoKwitansi");
			}
		}else
		{	
			if ($tgl != "" && $tgl1 !="")
			{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out from kwitansipenjualan A,transaction_kwitansi B,mutasi_cash C
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi
and A.Typebayar='CASH' and A.Active='1' and A.CreatedOn between '".$tgl."' and '".$tgl1."'");
			}else{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out from kwitansipenjualan A,transaction_kwitansi B,mutasi_cash C
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi
and A.Active='1' and A.Typebayar='CASH' group by A.NoKwitansi");
			}
		}
		//var_dump($this->db->last_query());exit;
		return $query->result();
	}
	
	function getMutasibeli($tgl,$tgl1,$tipebayar)
	{
		$tes = "";
		$tgl1;
		if ($tipebayar=="B")
		{
			if ($tgl != "" && $tgl1 !="")
			{ 
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out,
C.KodeBank,D.Bankname from kwitansi A,transaction_kwitansi B,mutasi_bank C, master_bank D
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi and C.Kodebank=D.KodeBank
and A.Typebayar='BANK' and A.Active='1' and A.CreatedOn between '".$tgl."' and '".$tgl1."' group by A.NoKwitansi");
			}else{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out,
C.KodeBank,D.Bankname from kwitansi A,transaction_kwitansi B,mutasi_bank C, master_bank D
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi and C.Kodebank=D.KodeBank
and A.Active='1' and A.Typebayar='BANK' group by A.NoKwitansi");
			}	
			
		}else if($tipebayar=="G")
		{
			if ($tgl != "" && $tgl1 !="")
			{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out,
C.Nogiro,C.Bankname from kwitansi A,transaction_kwitansi B,mutasi_giro C
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi
and A.Typebayar='GIRO' and A.Active='1' and A.CreatedOn between '".$tgl."' and '".$tgl1."' group by A.NoKwitansi");
			}else{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out,
C.Nogiro,C.Bankname from kwitansi A,transaction_kwitansi B,mutasi_giro C
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi
and A.Active='1' and A.Typebayar='GIRO' group by A.NoKwitansi");
			}
		}else
		{
			if ($tgl != "" && $tgl1 !="")
			{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out from kwitansi A,transaction_kwitansi B,mutasi_cash C
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi
and A.Typebayar='CASH' and A.Active='1' and A.CreatedOn between '".$tgl."' and '".$tgl1."' group by A.NoKwitansi");
			}else{
				$query = $this->db->query("select A.NoKwitansi,A.TotalQuantity,B.NoFaktur,C.TotalAmount_In,C.TotalAmount_Out from kwitansi A,transaction_kwitansi B,mutasi_cash C
where A.NoKwitansi=B.NoKwitansi and B.NoKwitansi = C.NoKwitansi
and A.Active='1' and A.Typebayar='CASH' group by A.NoKwitansi");
			}	
		}
		//var_dump($this->db->last_query());exit;
		return $query->result();
	}
}
?>